<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('合同管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>客户名称：</p>
                                <input type="text" id="customerName"  name="params[customerName]"/>
                            </li>
                            <li>
                                <p>合同编号：</p>
                                <input type="text" name="contractNo"/>
                            </li>
                            <li>
                                <p>合同名称：</p>
                                <input type="text" name="contractName"/>
                            </li>
                            <li>
                                <p>合同类型：</p>
                                <select name="contractType" th:with="type=${@dict.getType('contract_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>合同状态：</p>
                                <select name="contractStatus" th:with="type=${@dict.getType('contract_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>销售人员：</p>
                                <input type="text" name="saleBy"/>
                            </li>
                            <li class="select-time">
                                <p>合同日期：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始日期" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束日期" name="params[endCreateTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="crm:contract:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-info multiple disabled" onclick="javascript:transferPerson();" shiro:hasPermission="crm:contract:transfer">
                    <i class="fa fa-exchange"></i> 转交
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="crm:contract:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
    	var auditFlag=[[${@permission.hasPermi('crm:contract:audit')}]];
        var editFlag = [[${@permission.hasPermi('crm:contract:edit')}]];
        var removeFlag = [[${@permission.hasPermi('crm:contract:remove')}]];
        var contractTypeDatas = [[${@dict.getType('contract_type')}]];
        var contractStatusDatas = [[${@dict.getType('contract_status')}]];
        var prefix = ctx + "crm/contract";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
		        sortName: "createTime",
		        sortOrder: "desc",
                modalName: "合同记录",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'contractId', 
                    title : '合同ID',
                    visible: false
                },
                {
                    field : 'customerId', 
                    title : '客户id',
                    visible: false
                },
                {
                    field : 'customer.customerName', 
                    title : '客户名称',
		            sortable: true
                },
                {
                    field : 'totalMoney', 
                    title : '合同金额',
		            sortable: true
                },
                {
                    field : 'contractNo', 
                    title : '合同编号',
		            sortable: true
                },
                {
                    field : 'contractName', 
                    title : '合同名称',
		            sortable: true,
		            formatter: function(value, row, index) {
		            	return '<a style="color:blue;" href="javascript:void(0)" title="查看详情" onclick="$.operate.detail(\'' +row.contractId + '\')">'+value+'</a> ';
	                }
                },
                {
                    field : 'contractType', 
                    title : '合同类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(contractTypeDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'contractStatus', 
                    title : '合同状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(contractStatusDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'dateStart', 
                    title : '合同日期',
                    formatter: function(value, row, index) {
                        return value.substring(0,10)+'--'+row.dateEnd.substring(0,10);
                     },
 		            sortable: true
                },
                {
                    field : 'signDate', 
                    title : '合同签署时间',
                    formatter: function(value, row, index) {
                        return value.substring(0,10);
                     },
 		            sortable: true
                },
                {
                    field : 'signBy', 
                    title : '合同签署人',
		            sortable: true
                },
                {
                    field : 'sourceBelongTo', 
                    title : '原负责人',
                    visible: false,
		            sortable: true
                },
                {
                    field : 'belongTo', 
                    title : '负责人',
		            sortable: true
                },
                {
                    field : 'trasferDate', 
                    title : '转交时间',
                    visible: false,
		            sortable: true
                },
                {
                    field : 'trasferTo', 
                    title : '转交人',
                    visible: false,
		            sortable: true
                },
                {
                    field : 'createBy', 
                    title : '录入人',
		            sortable: true
                },
                {
                    field : 'createTime', 
                    title : '录入时间',
		            sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.contractStatus=="1"){
                        	actions.push('<a class="btn btn-primary btn-xs ' + auditFlag + '" href="javascript:void(0)" onclick="auditOk(\'' + row.contractId + '\')"><i class="fa fa-check"></i>审核通过</a> ');
                        	actions.push('<a class="btn btn-danger btn-xs ' + auditFlag + '" href="javascript:void(0)" onclick="auditNo(\'' + row.contractId + '\')"><i class="fa fa-reply"></i>驳回</a> ');
                        }
                        else if(row.contractStatus=="3"){
                        	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.contractId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        }
                        else if(row.contractStatus=="0"){
                        	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.contractId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.contractId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function auditOk(contractId)
        {        	
        	$.modal.confirm("确认审核通过吗？", function() {
        		$.operate.post(prefix + "/auditOk/"+contractId);
        	});        	
        }
        
        function auditNo(contractId)
        {        	
        	$.modal.confirm("确认驳回吗？", function() {
        		$.operate.post(prefix + "/auditNo/"+contractId);
        	});        	
        }
        
        /* 转交给其他人 */
		function transferPerson() {
			var contractId = $.table.selectColumns("contractId");
			if (contractId.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}	
			var url = ctx + 'crm/transfer/transferPerson?ids=' + contractId.join()+"&businessType=Contract";
			$.modal.open("转给其它团队成员（变更负责人）", url);
		}
    </script>
</body>
</html>